﻿using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;
using MvcArchStarter.Core.Ioc;
using MvcArchStarter.WebUI.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Unity.Mvc3;

namespace MvcArchStarter.WebUI
{
    public class Bootstrapper
    {
        public static void Initialize()
        {
            var container = BuildUnityContainer(new FindTypesInConfiguration());
            DependencyResolver.SetResolver(new WebUiDependencyResolver(container));
        }

        private static IUnityContainer BuildUnityContainer(ITypeFinder typeFinder)
        {
            var container = new UnityContainer();
            //Setup the container for interception
            container.AddNewExtension<Interception>();
            DependencyDiscovery discovery = new DependencyDiscovery(container, typeFinder, new CustomBehavior());
            discovery.LoadContainer();

            return container;
        }
    }
}